Imports System
Imports System.Web

Imports MetaSapiens.PageMethods

Public Class HttpHandlerBehind
  Implements IHttpHandler

  Private _context As HttpContext

  Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
    _context = context
    If Not PageMethodsEngine.InvokeMethod(Me, True) Then
      Throw New Exception("Page method not found!")
    End If
  End Sub

  Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
    Get
      Return False
    End Get
  End Property

  <PageMethod(True), UrlFormat("~/HttpHandlerBehind.ashx?i={i}")> _
  Public Sub SampleMethod(ByVal i As Integer)
    _context.Response.ContentType = "text/plain"
    _context.Response.Write("Hello from HTTP handler (code behind). i = " + i)
  End Sub

End Class
